package com.yn.pet.controller.app;


import com.yn.common.core.domain.AjaxResult;
import com.yn.pet.controller.app.biz.APhoneWhiteListBizService;
import com.yn.pet.controller.pc.request.PhoneWhiteListRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 电话白名单表 前端控制器
 * </p>
 *
 * @author xuquanjun
 * @since 2025-08-08
 */
@RestController
@RequestMapping("/front/sosContact")
@Slf4j
@Api(tags = "app端——电话白名单")
@RequiredArgsConstructor
public class APhoneWhitelistController {
    private final APhoneWhiteListBizService phoneWhiteListService;


    /**
     * 添加联系人白名单
     * @param request 请求参数
     * @return 响应结果
     */
    @PostMapping("save")
    @ApiOperation("添加联系人")
    public AjaxResult addConcat(@RequestBody @Validated PhoneWhiteListRequest request) {
        log.info("添加联系人白名单入参 request:{}",request);
        if(request.getDeviceId()==null)
            return AjaxResult.error("设备id不能为空");
        phoneWhiteListService.addConcat(request);
        return AjaxResult.success("添加成功");
    }

    /**
     * 删除联系人白名单
     * @param phoneId 联系人id
     * @return 响应结果
     */
    @PostMapping("delete/{phoneId}")
    @ApiOperation("删除联系人")
    public AjaxResult deleteConcat(@PathVariable @NotNull @ApiParam("联系人id") Long phoneId) {
        log.info("删除联系人白名单入参 phoneId:{}",phoneId);
        phoneWhiteListService.deleteConcat(phoneId);
        return AjaxResult.success("删除成功");
    }

    /**
     * 修改联系人白名单
     * @param request 请求参数
     * @return 响应结果
     */
    @PostMapping("update")
    @ApiOperation("修改联系人信息")
    public AjaxResult updateConcat(@RequestBody @Validated PhoneWhiteListRequest request) {
        log.info("修改联系人白名单入参 request:{}",request);
        if(request.getPhoneId()==null)
            return AjaxResult.error("联系人id不能为空");
        phoneWhiteListService.updateConcat(request);
        return AjaxResult.success("修改成功");
    }

    /**
     * 查询联系人列表
     * @param deviceId 设备id
     * @param phoneNumber 电话号码
     * @param name 姓名
     * @param sign 类型(1,2,3)
     * @return List<PhoneWhiteListResponse>
     */
    @GetMapping("list")
    @ApiOperation("查询联系人列表")
    public AjaxResult list(@RequestParam @NotNull @ApiParam("设备id") Long deviceId,
                           @RequestParam @ApiParam("电话号码") String phoneNumber,
                           @RequestParam @ApiParam("姓名") String name,
                           @RequestParam @ApiParam("类型(1,2,3)") String sign) {
        log.info("查询联系人列表入参 phoneNumber:{},name:{},sign:{}",phoneNumber,name,sign);
        return AjaxResult.success(phoneWhiteListService.list(deviceId,phoneNumber,name,sign));
    }

    /**
     * 根据id查询联系人信息
     * @param phoneId 联系人id
     * @return PhoneWhiteListResponse
     */
    @GetMapping("detail/{phoneId}")
    @ApiOperation("查询联系人详情")
    public AjaxResult queryById(@PathVariable @NotNull @ApiParam("联系人id") Long phoneId) {
        log.info("查询联系人详情入参 phoneId:{}",phoneId);
        return AjaxResult.success(phoneWhiteListService.queryById(phoneId));
    }


    /**
     * 查询字典数据
     * @param dictType 字典类型 phone_white_list_sign
     * @return 字典数据
     */
    @GetMapping("queryMapByDictType")
    @ApiOperation("查询字典数据")
    public AjaxResult queryMapByDictType(@ApiParam(value = "字典类型", required = true) @RequestParam(required = true) @NotBlank String dictType) {
        log.info("查询字典数据入参：dictType:{}",dictType);
        return AjaxResult.success(phoneWhiteListService.queryNoticeTypeByDictType(dictType));
    }

}
